#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	string s;
	map<string, string> key;
	for(int i = 0;i < n;i++){
		string n, m;
		cin >> n >> m;
		key[n] = m; 
	}
	cin >> s;
	string p;
	for(int i = 0;i < s.size(); i++){
		if(s[i] >= 'a' && s[i] <= 'z'){
			p+=s[i];
		}
		else{
			if(p.size() != 0 && key.count(p) != 0){
				cout << key[p];
			}
			else if(p.size() != 0){
				cout << "UNK";
			}
		}
	}
	if(p.size() != 0 && key.count(p) != 0){
		cout << key[p];
	}
	else if(p.size() != 0){
		cout << "UNK";
	}
}